//初始化
$(function(){
	initBase();//初始化基本信息
	
	initData();//初始化数据信息
	
});


/**
 * 初始化基本信息
 * @returns
 */
function initBase(){
	//显示当前时间
	$("#currentDate").text(showTime());
}

/**
 * 初始化数据信息
 * @returns
 */
function initData(){
	getWorkList();//工作动态
	getNoticeList();// 通知公告动态
	getBiddingList();//竞价公告
	getwiningList();//中标公告
	getEditList();//变更公告
	getFlowList();//流标公告
}


/**
 * 工作动态
 */
function getWorkList(){
	$.ajax({
		type: "post",
		url:  "../web/getAutoNotice?type=51&pageSize=8",
		success: function(data){
			var html='';
			for (var i = 0; i < data.length; i++) {
				var date=new Date(Date.parse(data[i].createTime.replace(/-/g, "/")));
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>20){
					title=title.substring(0,20)+'......';
				}
				//<li><a href="#"><span class="main_txt_title">包河区政府网上竞价系统正式投入使入使用……</span><span class="main_txt_time">2016年11月9日</span></a></</li>
				html+='<li>'
					+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title">'+title+'</span><span class="main_txt_time">'+date.Format("yyyy年MM月dd日")+'</span></a>'
					+'</li>';
			}
			$("#contentList_work").html(html);
			
		},
		error: function(res){
			//alert(3);
		}
	});

}

/**
 * 通知公告动态
 */
function getNoticeList(){
	$.ajax({
		type: "post",
		url:  "../web/getAutoNotice?type=52&pageSize=8",
		success: function(data){
			var html='';
			for (var i = 0; i < data.length; i++) {
				var date=new Date(Date.parse(data[i].createTime.replace(/-/g, "/")));
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>20){
					title=title.substring(0,20)+'......';
				}
				//<li><a href="#"><span class="main_txt_title">包河区政府网上竞价系统正式投入使入使用……</span><span class="main_txt_time">2016年11月9日</span></a></</li>
				html+='<li>'
					+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title">'+title+'</span><span class="main_txt_time">'+date.Format("yyyy年MM月dd日")+'</span></a>'
					+'</li>';
			}
			$("#contentList_notice").html(html);
			
		},
		error: function(res){
			//alert(3);
		}
	});

}


/**
 * 竞价公告
 */
function getBiddingList(){
	$.ajax({
		type: "post",
		url:  "../web/getAutoNotice?type=31&pageSize=8",
		success: function(data){
			//alert(JSON.stringify(data));
			var html='';
			for (var i = 0; i < data.length; i++) {
				var date=new Date(Date.parse(data[i].createTime.replace(/-/g, "/")));
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>28){
					title=title.substring(0,28)+'......';
				}
				if(data[i].isOpen==0){//未开标
					html+='<li>'
						+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title"><span class="txt_red">【未开拍】</span>'+title+'</span><span class="main_txt_time">'+date.Format("yyyy年MM月dd日")+'</span></a>'
						+'</li>';
				}else if(data[i].isOpen==1){//已开标
					html+='<li>'
						+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title"><span class="txt_green">【已结束】</span>'+title+'</span><span class="main_txt_time">'+date.Format("yyyy年MM月dd日")+'</span></a>'
						+'</li>';
				}
			}
			$("#bidInfoList").html(html);
			
		},
		error: function(res){
			//alert(3);
		}
	});

}


/**
 * 中标公告
 */
function getwiningList(){
	$.ajax({
		type: "post",
		url:  "../web/getAutoNotice?type=32&pageSize=3",
		success: function(data){
			//alert(JSON.stringify(data));
			var html='';
			for (var i = 0; i < data.length; i++) {
				var date=new Date(Date.parse(data[i].createTime.replace(/-/g, "/")));
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>28){
					title=title.substring(0,28)+'......';
				}
				if(data[i].isOpen==2){//正在公示
					html+='<div class="main_txt1">'
						 +'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title"><span class="txt_red">【正在公示】</span>'+title+'</span><span class="main_txt_time">'+date.Format("yyyy年MM月dd日")+'</span></a>'
						 +'</div>';
				}else if(data[i].isOpen==3){//公示结束
					html+='<div class="main_txt1">'
						 +'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title"><span class="txt_green">【公示结束】</span>'+title+'</span><span class="main_txt_time">'+date.Format("yyyy年MM月dd日")+'</span></a>'
						 +'</div>';
				}
			}
			$("#winingInfoList").html(html);
			
		},
		error: function(res){
			//alert(3);
		}
	});

}

/**
 * 变更公告
 */
function getEditList(){
	$.ajax({
		type: "post",
		url:  "../web/getAutoNotice?type=34&pageSize=3",
		success: function(data){
			//alert(JSON.stringify(data));
			var html='';
			for (var i = 0; i < data.length; i++) {
				var date=new Date(Date.parse(data[i].createTime.replace(/-/g, "/")));
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>13){
					title=title.substring(0,13)+'......';
				}
				//alert(data[i].isOpen);
				if(data[i].isOpen==2){//正在公示
					html+='<div class="main_txt1">'
						+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title2"><span class="txt_red">【正在公示】</span>'+title+'</span></a></div>';
				}else if(data[i].isOpen==3){//公示结束
					html+='<div class="main_txt1">'
						+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title2"><span class="txt_green">【公示结束】</span>'+title+'</span></a></div>';
				}
			}
			$("#editInfoList").html(html);
			
		},
		error: function(res){
			//alert(3);
		}
	});

}


/**
 * 流标公告
 */
function getFlowList(){
	$.ajax({
		type: "post",
		url:  "../web/getAutoNotice?type=33&pageSize=3",
		success: function(data){
			//alert(JSON.stringify(data));
			var html='';
			for (var i = 0; i < data.length; i++) {
				var date=new Date(Date.parse(data[i].createTime.replace(/-/g, "/")));
				var top=data[i].title;
				var title=data[i].title;
				if(title.length>13){
					title=title.substring(0,13)+'......';
				}
				//alert(data[i].isOpen);
				if(data[i].isOpen==2){//正在公示
					html+='<div class="main_txt1">'
						+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title2"><span class="txt_red">【正在公示】</span>'+title+'</span></a></div>';
				}else if(data[i].isOpen==3){//公示结束
					html+='<div class="main_txt1">'
						+'<a href="../web/getWebDetail?id='+data[i].id+'" target="_blank"><span class="main_txt_title2"><span class="txt_green">【公示结束】</span>'+title+'</span></a></div>';
				}
			}
			$("#flowInfoList").html(html);
			
		},
		error: function(res){
			//alert(3);
		}
	});
	
}



/******************************公共工具方法*************************************/

/**
 * 格式化时间
 * @returns
 */
function showTime() {
	var date = new Date();
	this.year = date.getFullYear();
	this.month = date.getMonth() + 1;
	this.date = date.getDate();
	this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
	this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
	this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
	this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
	var currentTime = this.year + "年"
					+ this.month + "月" 
					+ this.date + "日           "
					+ this.day+"      "
					+ this.hour 
					+ ":"+ this.minute  
					//":"+ this.second + " "
					;
	return currentTime;
}

/**
 * 时间格式化方法
 */
Date.prototype.Format = function (fmt) { //
    var o = {
        "M+": this.getMonth() + 1, // 月份
        "d+": this.getDate(), // 日
        "h+": this.getHours(), // 小时
        "m+": this.getMinutes(), // 分
        "s+": this.getSeconds(), // 秒
        "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
        "S": this.getMilliseconds() // 毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}




